package com.etc.security.controller;

import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.etc.common.Code;
import com.etc.common.CodeMessage;

/**
 * 
 * Filename:    TaskController.java  
 * Description:   权限测试
 * Copyright:   Copyright (c) 2018-2019 All Rights Reserved.
 * Company:     chinasofti.com Inc.
 * @author:     mazheng 
 * @version:    1.0  
 * Create at:   2020年3月4日 下午7:17:23  
 *  
 * Modification History:  
 * Date         Author      Version     Description  
 * ------------------------------------------------------------------  
 * 2020年3月4日      mazheng      1.0         1.0 Version  
 *
 */
@Api(value = "/tasks", tags = "ロールテスト")
@RestController("tasks1")
@RequestMapping("/tasks")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "sucess"),
        @ApiResponse(code = 205, message = "ロール権限がありません")
})

public class TaskController {


    @GetMapping
    public String listTasks(){
        return "任务列表";
    }

    @ApiOperation("ADMINテスト")
    @PostMapping
    @ApiImplicitParam(paramType = "header", name = "Authorization", value = "ユーザ識別子", required = true, dataType = "string", example = "Bearer-eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNTk5ODY5NzM5MCIsImlzcyI6InJjY3AiLCJleHAiOjE2MTI0ODg5ODgsImlhdCI6MTYxMTg4NDE4OCwicm9sIjoiUk9MRV9BRE1JTiJ9.GllT_I5MHV0R7GQ0LZmtYM-ihpemn9OYCEkBeFa6JU3HXxA40PB6d2H1bKT7PZMidL3pi11wPdMaMGK0pqKe0Q")
    @PreAuthorize("hasRole('ROLE_ADMIN')")

    public String newTasks(){
        return "创建了一个新的任务";
    }

    @ApiOperation("USERテスト")
    @PreAuthorize("hasRole('ROLE_USER')")
    @PostMapping("/{taskId}")
    @ApiImplicitParam(paramType = "header", name = "Authorization", value = "ユーザ識別子", required = true, dataType = "string", example = "Bearer-eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNTk5ODY5NzM5MCIsImlzcyI6InJjY3AiLCJleHAiOjE2MTI0ODg5ODgsImlhdCI6MTYxMTg4NDE4OCwicm9sIjoiUk9MRV9BRE1JTiJ9.GllT_I5MHV0R7GQ0LZmtYM-ihpemn9OYCEkBeFa6JU3HXxA40PB6d2H1bKT7PZMidL3pi11wPdMaMGK0pqKe0Q")
    public CodeMessage updateTasks(@PathVariable("taskId")Integer id){
        return CodeMessage.success(Code.SUCESS, null);
    }

    @ApiOperation("ADMINテスト config")
    @DeleteMapping("/{taskId}")
    @ApiImplicitParam(paramType = "header", name = "Authorization", value = "ユーザ識別子", required = true, dataType = "string", example = "Bearer-eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxNTk5ODY5NzM5MCIsImlzcyI6InJjY3AiLCJleHAiOjE2MTI0ODg5ODgsImlhdCI6MTYxMTg4NDE4OCwicm9sIjoiUk9MRV9BRE1JTiJ9.GllT_I5MHV0R7GQ0LZmtYM-ihpemn9OYCEkBeFa6JU3HXxA40PB6d2H1bKT7PZMidL3pi11wPdMaMGK0pqKe0Q")
    public String deleteTasks(@PathVariable("taskId")Integer id){

        return "DELETE"+id;
    }
}
